package com.dexilaonian.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.adpter.BindPersonAdapter;
import com.dexilaonian.bean.Person_BindBean;
import com.dexilaonian.ui.BaseActivity;
import com.dexilaonian.utils.Constant;
import com.dexilaonian.utils.JsonUtil;
import com.dexilaonian.utils.Okhttp;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

public class Smart_guardActivity extends BaseActivity {
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.base_title_service3)
    TextView baseTitleService3;
    @Bind(R.id.btn_add_guard)
    Button btnAddGuard;

    @Override
    public int getLayoutID() {
        return R.layout.activity_smart_guard;
    }

    @Override
    public void initView() {
        initPerson();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        baseTitleService3.setText("智能守护");
    }

    @OnClick({R.id.back, R.id.btn_add_guard})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.btn_add_guard:
                Intent intent = new Intent(Smart_guardActivity.this, Bind_GuardActivity.class);
                startActivity(intent);
                break;
        }
    }

        private void initPerson() {
            showProgressBar(true);
            String bind_url = Constant.base_url + "/health_record/list.do";
            Map<String, String> parm = new HashMap<>();
            Okhttp.postString(true, bind_url, parm, new Okhttp.CallBac() {
                @Override
                public void onError(Call call, Exception e, String state, int id) {
                    showProgressBar(false);
                    showToast(state);
                }

                @Override
                public void onResponse(String response, int id) {
                    showProgressBar(false);
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        int status = Integer.parseInt(jsonObject.optString("status"));
                        if (status == 16 || status == 34) {
                            startActivity(new Intent(Smart_guardActivity.this, LoginActivity.class));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onNoNetwork(String state) {
                    showProgressBar(false);
                    showToast(state);
                }
            });
        }
    }
